/*
#include <stack>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <sstream>
using namespace std;
struct TreeNode{
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode(int x):val(x),left(NULL),right(NULL){}
};
TreeNode* buildTree(vector<int>& preorder, int left,int right,vector<int>& inorder,int start,int end){
	TreeNode* node=NULL;
	if(left<=right){
		node=new TreeNode(preorder[left]);
		int i;
		for(i=start;i<=end;i++){
			if(inorder[i]==preorder[left])
				break;
		}
		int tab=i-start;
		node->left=buildTree(preorder,left+1,left+tab,inorder,start,i-1);
		node->right=buildTree(preorder,left+tab+1,right,inorder,i+1,end);
	}
	return node;
} 
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
	TreeNode* tree=buildTree(preorder,0,preorder.size()-1,inorder,0,inorder.size()-1);
	return tree;
}
void printPreorder(TreeNode *tree){
	if(tree!=NULL){
		cout<<tree->val<<",";
		printPreorder(tree->left);
		printPreorder(tree->right);
	}
}
void printInorder(TreeNode *tree){
	if(tree!=NULL){
		printInorder(tree->left);
		cout<<tree->val<<",";
		printInorder(tree->right);
	}
}
int main(){
	int a[]={1,2,4,5,3,6};
	int b[]={4,2,5,1,6,3};
	vector<int> preorder(a,a+sizeof(a)/sizeof(int));
	vector<int>inorder(b,b+sizeof(b)/sizeof(int));
	TreeNode* tree=buildTree(preorder,inorder);
	printPreorder(tree);
	cout<<endl;
	printInorder(tree);
	cout<<endl;
	system("pause");
}
*/